package mail.impl;

import java.util.ArrayList;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.search.SearchTerm;

import com.sun.mail.pop3.POP3Folder;

public class NewMailTerm extends SearchTerm {
  private ArrayList<String> uidList;
  private POP3Folder inbox;
  
  public NewMailTerm(ArrayList<String> uidList, POP3Folder inbox) {
    this.uidList = uidList;
    this.inbox = inbox;
  }

  public boolean match(Message msg) {
    if(uidList == null || uidList.size() == 0) {
      return true;
    }
    String uid;
    try {
      uid = inbox.getUID(msg);
    } catch (MessagingException e) {
      e.printStackTrace();
      return true;
    }
    if(uidList.contains(uid)) {
      return false;
    }
    return true;
  }
  
  public boolean equals(Object obj) {
    if (!(obj instanceof NewMailTerm))
      return false;
    return super.equals(obj);
  }

  
}
